package tony.aliyun.oss

import com.aliyun.oss.OSS
import java.io.InputStream
import tony.aliyun.oss.autoconfigure.AliyunOssProperties
import tony.core.oss.IOssService
import tony.core.utils.sanitizedPath

/**
 * MinioOssService is
 * @author tangli
 * @date 2025/10/09 16:58
 */
internal class AliyunOssService(
    private val aliyunOssClient: OSS,
    private val aliyunOssProperties: AliyunOssProperties,
) : IOssService {
    override fun putObject(
        path: String,
        inputStream: InputStream,
    ): String =
        aliyunOssClient.run {
            val sanitizedPath = sanitizedPath(path).removePrefix("/")
            putObject(aliyunOssProperties.bucketName, sanitizedPath, inputStream)
            "https://${aliyunOssProperties.bucketName}.${aliyunOssProperties.endpoint}/$sanitizedPath"
        }
}
